import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";
var _excluded = ["formItems", "onOk", "onCancel", "form"];

var _dec, _dec2, _dec3, _dec4, _class, _class2;

/**
 * EditFormModal.js - 个人中心的编辑模态框
 * @date 2018/11/15
 */
import React from 'react';
import { Modal, Form } from 'antd';
import { Bind } from 'lodash-decorators';
var EditFormModal = (_dec = Form.create({
  fieldNameProp: 'key'
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(EditFormModal, _React$PureComponent);

  var _super = _createSuper(EditFormModal);

  function EditFormModal() {
    _classCallCheck(this, EditFormModal);

    return _super.apply(this, arguments);
  }

  _createClass(EditFormModal, [{
    key: "handleOk",
    value: function handleOk() {
      var _this$props = this.props,
          onOk = _this$props.onOk,
          form = _this$props.form;

      if (_isFunction(onOk)) {
        form.validateFields(function (err, fieldsValue) {
          if (!err) {
            onOk(fieldsValue, form);
          }
        });
      }
    }
  }, {
    key: "handleCancel",
    value: function handleCancel() {
      var _this$props2 = this.props,
          onCancel = _this$props2.onCancel,
          form = _this$props2.form;

      if (_isFunction(onCancel)) {
        form.resetFields();
        onCancel(form);
      }
    }
  }, {
    key: "handleAfterClose",
    value: function handleAfterClose() {
      var form = this.props.form;
      form.resetFields();
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
          _this$props3$formItem = _this$props3.formItems,
          formItems = _this$props3$formItem === void 0 ? [] : _this$props3$formItem,
          onOk = _this$props3.onOk,
          onCancel = _this$props3.onCancel,
          form = _this$props3.form,
          modalProps = _objectWithoutProperties(_this$props3, _excluded);

      return /*#__PURE__*/React.createElement(Modal, Object.assign({}, modalProps, {
        onOk: this.handleOk,
        onCancel: this.handleCancel,
        afterClose: this.handleAfterClose
      }), /*#__PURE__*/React.createElement(Form, null, _isFunction(formItems) ? formItems(form) : formItems));
    }
  }]);

  return EditFormModal;
}(React.PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleOk", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleOk"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleCancel", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleCancel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleAfterClose", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleAfterClose"), _class2.prototype)), _class2)) || _class);
export { EditFormModal as default };